package com.eet.order.config;

import com.eet.order.constants.CommonConstants;
import org.springframework.amqp.core.Binding;
import org.springframework.amqp.core.BindingBuilder;
import org.springframework.amqp.core.DirectExchange;
import org.springframework.amqp.core.Queue;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
 * 消息队列配置类
 *
 * @author zheng.zhang
 */
@Configuration
public class RabbitMqConfiguration {

    @Bean
    public DirectExchange directExchange() {
        return new DirectExchange(CommonConstants.DIRECT_EXCHANGE, true, false);
    }

    @Bean
    public Queue emailQueue() {
        return new Queue(CommonConstants.DIRECT_EMAIL_QUEUE, true, false, false);
    }

    @Bean
    public Queue smsQueue() {
        return new Queue(CommonConstants.DIRECT_SMS_QUEUE, true, false, false);
    }

    @Bean
    public Queue weChatQueue() {
        return new Queue(CommonConstants.DIRECT_WECHAT_QUEUE, true, false, false);
    }

    @Bean
    public Binding emailBinding() {
        return BindingBuilder.bind(emailQueue())
                .to(directExchange())
                .with(CommonConstants.EMAIL);
    }
    @Bean
    public Binding smsBinding() {
        return BindingBuilder.bind(smsQueue())
                .to(directExchange())
                .with(CommonConstants.SMS);
    }
    @Bean
    public Binding wechatBinding() {
        return BindingBuilder.bind(weChatQueue())
                .to(directExchange())
                .with(CommonConstants.WECHAT);
    }

}
